package blog.entity;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResultJson implements Serializable {
    public static ResultJson USERNAME_NULL = ResultJson.isFail("账户名不能为空");
    public static ResultJson USERNAME_NONE = ResultJson.isFail("账户名不存在");
    public static ResultJson USERNAME_SHORTER = ResultJson.isFail("账户名长度至少6位");
    public static ResultJson USERNAME_LONGER = ResultJson.isFail("账户名过长，长度不能超过15位");
    public static ResultJson USERNAME_ILLEGAL_CONTENT = ResultJson.isFail("账户名包含非法信息");
    public static ResultJson PASSWORD_NULL = ResultJson.isFail("密码不能空");
    public static ResultJson PASSWORD_OLD_ERROR = ResultJson.isFail("旧密码错误");
    public static ResultJson PASSWORD_OLD_NULL = ResultJson.isFail("旧密码不能为空");
    public static ResultJson PASSWORD_NEW_NULL = ResultJson.isFail("新密码不能为空");
    public static ResultJson PASSWORD_NEW_SAME_ERROR = ResultJson.isFail("新密码不一致");
    public static ResultJson PASSWORD_ERROR = ResultJson.isFail("密码错误");
    public static ResultJson PASSWORD_SHORTER = ResultJson.isFail("密码长度至少6位");
    public static ResultJson PASSWORD_LONGER = ResultJson.isFail("密码长度不能超过16位");
    public static ResultJson PASSWORD_ILLEGAL_CONTENT = ResultJson.isFail("密码包含非法信息");
    public static ResultJson LOGIN_NONE = ResultJson.isFail("用户未登录");
    public static ResultJson CODE_IMG_ERROR = ResultJson.isFail("图片验证码错误");
    public static ResultJson CODE_PHONE_ERROR = ResultJson.isFail("手机验证码错误");
    public static ResultJson CODE_EMAIL_ERROR = ResultJson.isFail("邮箱验证码错误");
    public static ResultJson CODE_IMG_NULL = ResultJson.isFail("图片验证码为空");
    public static ResultJson CODE_PHONE_NULL = ResultJson.isFail("手机验证码为空");
    public static ResultJson CODE_EMAIL_NULL = ResultJson.isFail("邮箱验证码为空");
    public static ResultJson SYSTEM_ILLEGAL = ResultJson.isFail("非法操作");
    public static ResultJson UPDATE_ERROR = ResultJson.isFail("修改失败");
    public static ResultJson UPDATE_USED_ERROR = ResultJson.isFail("修改失败，正在使用中");
    public static ResultJson INSERT_ERROR = ResultJson.isFail("添加失败");
    public static ResultJson UPDATE_PART_ERROR = ResultJson.isFail("修改失败，部分信息未成功");
    public static ResultJson UPDATE_PART_USED_ERROR = ResultJson.isFail("修改失败，部分正在使用中无法修改");
    public static ResultJson UPDATE_SAME_ERROR_ = ResultJson.isFail("修改失败，相同数据，不进行任何操作");
    public static ResultJson ARGUMENT_NULL = ResultJson.isFail("操作失败，参数不能为空");
    public static ResultJson PARAMETER_NULL = ResultJson.isFail("操作失败，参数不能为空");
    public static ResultJson ARGUMENT_ILLEGAL = ResultJson.isFail("操作失败,参数非法");
    public static ResultJson PARAMETER_ILLEGAL = ResultJson.isFail("操作失败,参数非法");
    public static ResultJson SUCCESS = ResultJson.isSuccess();
    public static ResultJson FAIL = ResultJson.isFail("失败");
    public static ResultJson ERROR = ResultJson.isFail("错误");
    public static ResultJson NULL = ResultJson.isFail("空值");
    public static ResultJson NONE = ResultJson.isFail("不存在");
    public static ResultJson EXCEPTION = ResultJson.isFail("系统异常，请稍后重试");
    public static ResultJson FILE_NULL = ResultJson.isFail("文件不存在");
    public static ResultJson PATH_NULL = ResultJson.isFail("路径不存在");

    private boolean success;
    private String msg;
    private Object data;

    public static ResultJson isSuccess(Object obj){
        ResultJson resultJson = new ResultJson();
        resultJson.success = true;
        resultJson.data = obj;
        return resultJson;
    }
    private static ResultJson isSuccess(){
        ResultJson resultJson = new ResultJson();
        resultJson.success = true;
        return resultJson;
    }
    public static ResultJson isFail(String msg) {
        ResultJson resultJson = new ResultJson();
        resultJson.success = false;
        resultJson.msg = msg;
        return resultJson;
    }
    private static ResultJson isFail() {
        ResultJson resultJson = new ResultJson();
        resultJson.success = false;
        return resultJson;
    }
    public boolean getSuccess(){
        return this.success;
    }
    public ResultJson setSuccess(boolean success){
        this.success = success;
        return this;
    }
}
